package com.opengms.HydroModelsIntegration.Dao;

import com.opengms.HydroModelsIntegration.Domain.TreeNode;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.Iterator;

//import static java.lang.Compiler.command;

/**
 * @Author: David.Xiao
 * @Date: 2019/1/24 23:07
 * @Description:
 */
public class JsonHelper {

    public void analysisJson(Object object,Command command)
    {
        if(object instanceof JSONArray)
        {
            JSONArray jsonArray = (JSONArray) object;
            for(int i = 0;i<(jsonArray).size();i++)
            {
                analysisJson(jsonArray.get(i),command);

            }
        }
        else if(object instanceof JSONObject)
        {
            JSONObject jsonObject = (JSONObject) object;
            Iterator iterator = jsonObject.keys();
            while (iterator.hasNext())
            {
                String key = iterator.next().toString();
                Object obj = jsonObject.get(key);

                if(key.equals("matched"))
                {
                    JSONArray jsonArray1 =  (JSONArray)obj;
                    command.process(obj);
                }

                else if(obj instanceof JSONArray)
                {
//                    if(((JSONArray)obj).)
                    analysisJson((JSONArray)obj,command);
                }
                else if(obj instanceof JSONObject)
                {
                    JSONObject jsonObject1 = (JSONObject)obj;


                    analysisJson((JSONObject)obj,command);


                }
                else
                {
//                    System.out.println("正在遍历："+key+"-->"+obj.toString());
                }
            }
            String mapKey;
//            command.process(jsonObject);
        }
        else {

        }
    }
}
